package com.yearno.common.utils

import android.content.Context
import android.content.SharedPreferences

object SPUtil {

    private const val NAME = "app"
    private const val KEY_UID = "key_uid"

    private fun getSharedPreferences(context: Context): SharedPreferences {
        return context.getSharedPreferences(NAME, Context.MODE_PRIVATE)
    }

    fun saveUid(context: Context, userId: String) {
        getSharedPreferences(context).edit().putString(KEY_UID, userId).apply()
    }

    fun getUid(context: Context): String? {
        return getSharedPreferences(context).getString(KEY_UID, null)
    }

    /**
     * 保存一个字符串
     */
    fun setStringValue(context: Context, key: String, value: String?) {
        getSharedPreferences(context).edit().putString(key, value).apply()
    }

    /**
     * 获取一个字符串
     */
    fun getStringValue(context: Context, key: String): String? {
        return getSharedPreferences(context).getString(key, "")
    }

}